<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<title>天天好心情^_^</title>
	<%@ include file="layouts/top.jsp"%>
	<script type="text/javascript">
		function formatNowDate() {
			var today = new Date();
			var year = today.getFullYear();
			var month = today.getMonth() + 1;
			var day = today.getDate();
			var hrs = today.getHours();
			var min = today.getMinutes();
			var sec = today.getSeconds();
	
			if (month < 10) {
				month = "0" + month;
			}
			if (day < 10) {
				day = "0" + day;
			}
			if (hrs < 10) {
				hrs = "0" + hrs;
			}
			if (min < 10) {
				min = "0" + min;
			}
			if (sec < 10) {
				sec = "0" + sec;
			}
	
			$("#nowTime").val(year + "年" + month + "月" + day + "日"
					+ "  星期" + "日一二三四五六".charAt(today.getDay()) + "  "
					+ hrs + "时" + min + "分");
			$("#nowTime2").val(year + "年" + month + "月" + day + "日"
					+ "  星期" + "日一二三四五六".charAt(today.getDay()) + "  "
					+ hrs + "时" + min + "分");
			var textLength = $("#nowTime").val().length;
			$("#nowTime").css('width', textLength * 10 + 'px');
			$("#nowTime2").css('width', textLength * 10 + 'px');
		}
		setInterval("formatNowDate()", 1000);

		$(function() {
			$("#before").show();
			$("#after").hide();
		});
		
		function submitText() {
			var checkVal = $('input:radio[name="gender"]:checked').val();
			if (checkVal == null) {
				alert("请先选择您的心情分数!");
				return;
			} else if ($("#tel_text").val() == null || $("#tel_text").val().trim() == "") {
				alert("请先填写您的手机号!");
				return;
			}
			$.messager.confirm('系统提示', '确定提交心情吗?', function(r) {
				if (r) {
					$.post(getHttpRequestPath("submitMood"), {
						mood : checkVal,
						telephone : $("#tel_text").val()
					}, function(typesString) {
						var response = JSON.parse(typesString, function(key, value) {
							return value;
						});
						if (response.result.toLowerCase() == "success") {
							alert('提交成功!');
							$("#before").hide();
							$("#after").show();
							$("#moodText").val(response.score);
							$("#averageText").val(response.average);
							$("#rankText").val(response.rank);
						} else if (response.result.toLowerCase() == "noexist") {
							alert('该手机号未登记,请先联系管理员登记信息!');
							location.reload();
						} else if (response.result.toLowerCase() == "exists") {
							alert('该手机号今天已提交心情,请明天再来!');
							location.reload();
						} else {
							alert('提交出错!');
							location.reload();
						}
						
					}).error(_error);
				}
			});
		}
	</script>
</head>
<body>
	<div align="center" id="before">
		<table style="width:100%; text-align: center;">
			<tr><td><B>欢迎使用!</B></td></tr>
			<tr><td>现在是     <input type="text" id="nowTime" style="border: 0;" readonly="readonly" /></td></tr>
			<tr><td>
				您的心情是几分呢?<br>
				<input type="radio" name="gender" value="1" />1分<br>
				<input type="radio" name="gender" value="2" />2分<br>
				<input type="radio" name="gender" value="3" />3分<br>
				<input type="radio" name="gender" value="4" />4分<br>
				<input type="radio" name="gender" value="5" />5分<br>
				<input type="radio" name="gender" value="6" />6分<br>
				<input type="radio" name="gender" value="7" />7分<br>
				<input type="radio" name="gender" value="8" />8分<br>
				<input type="radio" name="gender" value="9" />9分<br>
				<input type="radio" name="gender" value="10" />10分<br>
			</td></tr>
			<tr><td>您的手机号为: <input type="number" id="tel_text" /></td></tr>
			<tr><td><input type="button" value="提交" onclick="submitText()"></td></tr>
		</table>
	</div>
	<div align="center" id="after">
		<table style="width:100%; text-align: center;">
			<tr><td><B>欢迎使用!</B></td></tr>
			<tr><td>现在是     <input type="text" id="nowTime2" style="border: 0;" readonly="readonly" /></td></tr>
			<tr><td>
				您目前选择的分数是<input type="text" id="moodText" style="width: 15px; border: 0;" readonly="readonly" />分，
				目前支行平均分值为<input type="text" id="averageText" style="width: 30px; border: 0;" readonly="readonly" />分，
				今天排在第<input type="text" id="rankText" style="width: 20px; border: 0;" readonly="readonly" />位
			</td></tr>
		</table>
	</div>
</body>

</html>